#ifndef __UNIT_H__
#define __UNIT_H__

#include "cocos2d.h"

USING_NS_CC;

enum DamageType
{
	CrashDamage,
};

enum UnitFacing
{
	Left, Right,
};

enum UnitDeadType
{
	NotDead,
	Dead,
	Ghost,
};
enum UnitTypeID
{
	TypeID_Player,
	TypeID_Monster
};

enum ClassID
{
	BASE_NONE,
	BASE_WARRIOR,
	BASE_MAGIC,
	BASE_THIEF,
	BASE_ARCHER,
};

enum Int32Value
{
	UNIT_GUID,
	MAP_ID,
	MONEY,
	JF,
	VALUE_STR,
	VALUE_DEX,
	VALUE_INT,
	VALUE_LUCK,
	VALUE_HP,
	VALUE_MAXHP,
	VALUE_MP,
	VALUE_MAXMP,
	VALUE_LEVEL,
	EXP,
	CLASS,
	TALENT,
	UNUSE_TALENT,
	MOVE_SPEED,
	JUMP_HIGH,
};


class Player;
class Monster;

class Unit : public CCSprite
{
public:
	Unit(UnitTypeID _UnitTypeID);
	~Unit();

	virtual int GetHeath() = 0;
	virtual void SetHeath(int _val) = 0;
	bool IsCastingSpell();
	void CastSpell(int _SpellID = 0);
	void Kill(Unit* Killed);
	void JustDead();
	void CreateLoot(Unit* Killer);
	void ShowDamageNumber(int Damage, int rowcount = 1, bool Crit = false);
	void DesTorySprite(CCSprite* pSprite);
	virtual void update(float diff);

	void DealDamage(Unit* victim, int _CleanDamage, DamageType _DamageType = CrashDamage);


	bool IsAlive()											{ if (m_UnitDeadType) return false; return true; }
	std::string GetName()									{ return m_Name; }
	UnitTypeID GetTypeId() const							{ return m_UnitTypeID; }
	UnitFacing GetFacing()									{ return m_PlayerFacing; }
	int GetGuid() const										{ return m_guid; }
	void SetDeadStatus(UnitDeadType _UnitDeadType)			{ m_UnitDeadType = _UnitDeadType; }
	void SetName(std::string _name)							{ m_Name = _name; }
	void SetFacing(UnitFacing facing)						{ m_PlayerFacing = facing; }
	void SetGuid(int value)									{ m_guid = value; }


	Player* ToPlayer()										{ if (GetTypeId() == TypeID_Player) return reinterpret_cast<Player*>(this); else return NULL; }
	Monster* ToMonster()									{ if (GetTypeId() == TypeID_Monster) return reinterpret_cast<Monster*>(this); else return NULL; }
	Player const* ToPlayer() const							{ if (GetTypeId() == TypeID_Player) return reinterpret_cast<Player const*>(this); else return NULL; }
	Monster const* ToMonster() const						{ if (GetTypeId() == TypeID_Monster) return reinterpret_cast<Monster const*>(this); else return NULL; }

private:
	std::string GetDamageNumber(std::string& number);



private:
	std::vector<CCSprite*> TempShowDamage;
	UnitTypeID m_UnitTypeID;
	UnitDeadType m_UnitDeadType;
	UnitFacing m_PlayerFacing;
	std::string m_Name;
	int m_guid;
};


#endif